package tmp

/**
 * Created by Administrator on 2015/3/13.
 */
case class AppVersion(v1: Int, v2: Int, v3: Int) extends Ordered[AppVersion] {
  override def compare(that: AppVersion): Int = {
    val (n1, n2, n3) = (v1 - that.v1, v2 - that.v2, v3 - that.v3)
    if (n1 != 0) n1
    else if (n2 != 0) n2
    else n3
  }
}

object AppVersion {
  private val pattern = """^(\d+)\.(\d+)\.(\d+)$""".r
  def apply(versionNo: String): AppVersion = {
    val pattern(n1, n2, n3) = versionNo
    AppVersion(n1.toInt, n2.toInt, n3.toInt)
  }
  val default = AppVersion(1, 0, 0)
}

object VersionTest extends App {

  println(AppVersion.default)

  println("1.1.12" < "1.1.0")
  println(AppVersion("1.2.0") < AppVersion("1.4.0"))

}
